// pages/carType/carType.js
import {
	carCateDetails
} from '../../api/car.js'
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		id: null,
		typename: null,
		$https: getApp().globalData.$https,
		swiper: {
			indicatorDots: false,
			vertical: false,
			autoplay: false,
			interval: 2000,
			duration: 500,
			current: 1,
		},
		controls:true,
		banner_list: '',
		car_list: [],
		new_list: [],
		newsLength: 0,
		video_list: [],
		videoLength: 0,
		fuwu_list: [{
			id: 0,
			imgUrl: '../../img/index/rk_1.png',
			name: '经销商查询'
		},
		{
			id: 1,
			imgUrl: '../../img/index/rk_2.png',
			name: '服务商查询'
		},
		{
			id: 3,
			imgUrl: '../../img/index/rk_3.png',
			name: '运营商查询'
		}],
		nav: [{
			id: 0,
			url: '../../img/icon/home1.png',
			name: '首页'
		}, {
			id: 1,
			url: '../../img/icon/selection.png',
			name: '选车'
		}, {
			id: 2,
			url: '../../img/icon/find.png',
			name: '发现'
		}, {
			id: 3,
			url: '../../img/icon/my.png',
			name: '我的'
		}]
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function (options) {
		this.setData({
			id: options.id
		})
		this.carCateDetails()
	},
	jumpnews() {
		wx.navigateTo({
			url: '/packageA/Newslist/Newslist',
		})
	},
	jumpnewsid(e) {
		var id = e.currentTarget.dataset.id
		wx.navigateTo({
			url: '/packageA/Newsdetail/Newsdetail?id=' + id,
		})
	},
	jumpsecar() {
		wx.navigateTo({
			url: '../allCarType/allCarType?id=' + this.data.id,
		})
	},
	applicaClick(e) {
		var index = e.currentTarget.dataset.index
		wx.navigateTo({
			url: '../../packageA/query/query?index=' + index
		})
	},
	carDetail(e) {
		var id = e.currentTarget.dataset.id
		wx.navigateTo({
			url: '../carDetail/carDetail?id=' + id
		})
	},
	async carCateDetails() {
		var res = await carCateDetails({
			id: this.data.id
		})
		this.setData({
			banner_list: res.miniImg,
			car_list: res.cars,
			new_list: res.news,
			newsLength: res.news ? res.news.length : 0,
			video_list: res.videosList,
			videoLength: res.videosList ? res.videosList.length : 0,
			typename: res.cars[0].category
		})
	},
	leftClick() {
		var swiper = this.data.swiper;
		var car_list = this.data.car_list;
		var current = swiper.current;
		swiper.current = current > 0 ? current - 1 : car_list.length - 1;
		this.setData({
			swiper: swiper,
		})

	},
	rightClick() {
		var swiper = this.data.swiper;
		var car_list = this.data.car_list;
		var current = swiper.current;
		swiper.current = current < (car_list.length - 1) ? current + 1 : 0;
		this.setData({
			swiper: swiper,
		})

	},
	screenchange(e) {
		let fullScreen = e.detail.fullScreen //值true为进入全屏，false为退出全屏
		if (!fullScreen) { //退出全屏
			this.setData({
				controls: true
			})
		} else { //进入全屏
			this.setData({
				controls: false
			})
		}
	},
	goindex(e) {
		var id = e.currentTarget.dataset.id
		if (id == 0) {
			wx.switchTab({
				url: '/pages/home/home',
			})
		} else if (id == 1) {
			wx.switchTab({
				url: '/pages/selection/selection',
			})
		} else if (id == 2) {
			wx.switchTab({
				url: '/pages/find/find',
			})
		} else if (id == 3) {
			wx.switchTab({
				url: '/pages/my/my',
			})
		}
	},
	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady: function () {
	},


	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow: function () {

	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide: function () {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload: function () {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh: function () {

	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom: function () {

	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage: function () {

		return {
			title: '远程汽车',
			path: '/pages/carType/carType?id=' + this.data.id,
			imageUrl: '../../img/share/type' + this.data.id + '.jpg'
		}
	}
})